PCL
DrizzleData.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.4.0
6 // ----------------------------------------------------------------------------
7 // pcl/DrizzleData.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_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/SurfaceSpline.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 
112 class PCL_CLASS DrizzleData
113 {
114 public:
115 
122 
128 
134 
140 
146 
151 
155  DrizzleData() = default;
156 
160  DrizzleData( const DrizzleData& ) = default;
161 
165  DrizzleData( DrizzleData&& ) = default;
166 
187  DrizzleData( const String& filePath, bool ignoreIntegrationData = false )
188  {
189  Parse( filePath, ignoreIntegrationData );
190  }
191 
209  DrizzleData( const XMLDocument& xml, bool ignoreIntegrationData = false )
210  {
211  Parse( xml, ignoreIntegrationData );
212  }
213 
229  DrizzleData( const XMLElement& element, bool ignoreIntegrationData = false )
230  {
231  Parse( element, ignoreIntegrationData );
232  }
233 
237  virtual ~DrizzleData()
238  {
239  }
240 
244  DrizzleData& operator =( const DrizzleData& ) = default;
245 
249  DrizzleData& operator =( DrizzleData&& ) = default;
250 
261  const String& SourceFilePath() const
262  {
263  return m_sourceFilePath;
264  }
265 
272  void SetSourceFilePath( const String& filePath )
273  {
274  m_sourceFilePath = File::FullPath( filePath );
275  }
276 
287  const String& CFASourceFilePath() const
288  {
289  return m_cfaSourceFilePath;
290  }
291 
298  void SetCFASourceFilePath( const String& filePath )
299  {
300  m_cfaSourceFilePath = File::FullPath( filePath );
301  }
302 
314  const String& CFASourcePattern() const
315  {
316  return m_cfaSourcePattern;
317  }
318 
328  void SetCFASourcePattern( const String& cfaPattern )
329  {
330  m_cfaSourcePattern = cfaPattern;
331  }
332 
350  {
351  return m_alignTargetFilePath;
352  }
353 
360  void SetAlignmentTargetFilePath( const String& filePath )
361  {
362  m_alignTargetFilePath = File::FullPath( filePath );
363  }
364 
370  int ReferenceWidth() const
371  {
372  return m_referenceWidth;
373  }
374 
380  int ReferenceHeight() const
381  {
382  return m_referenceHeight;
383  }
384 
391  void SetReferenceDimensions( int width, int height )
392  {
393  m_referenceWidth = width;
394  m_referenceHeight = height;
395  }
396 
401  int NumberOfChannels() const
402  {
403  return m_location.Length();
404  }
405 
413  const DPoint& AlignmentOrigin() const
414  {
415  return m_alignmentOrigin;
416  }
417 
429  void SetAlignmentOrigin( const DPoint& p0 )
430  {
431  m_alignmentOrigin = p0;
432  }
433 
441  const Matrix& AlignmentMatrix() const
442  {
443  return m_H;
444  }
445 
452  void SetAlignmentMatrix( const Matrix& H )
453  {
454  m_H = H;
455  }
456 
463  bool HasAlignmentMatrix() const
464  {
465  return !m_H.IsEmpty();
466  }
467 
476  const vector_spline& AlignmentSplines() const
477  {
478  return m_S;
479  }
480 
488  void SetAlignmentSplines( const vector_spline& S )
489  {
490  m_S = S;
491  }
492 
500  bool HasAlignmentSplines() const
501  {
502  return m_S.IsValid();
503  }
504 
513  const vector_spline& AlignmentInverseSplines() const
514  {
515  return m_Sinv;
516  }
517 
525  void SetAlignmentInverseSplines( const vector_spline& Sinv )
526  {
527  m_Sinv = Sinv;
528  }
529 
538  {
539  return m_Sinv.IsValid();
540  }
541 
586  void GetLocalDistortionModel( distortion_vector& P1, distortion_vector& D2,
587  distortion_vector& P2, distortion_vector& D1,
588  weight_vector& W,
589  int& order, float& regularization, bool& extrapolate )
590  {
591  P1 = m_LP1;
592  D2 = m_LD2;
593  P2 = m_LP2;
594  D1 = m_LD1;
595  W = m_LW;
596  order = m_localDistortionOrder;
597  regularization = m_localDistortionRegularization;
598  extrapolate = m_localDistortionExtrapolation;
599  }
600 
647  void SetLocalDistortionModel( const distortion_vector& P1, const distortion_vector& D2,
648  const distortion_vector& P2, const distortion_vector& D1,
649  const weight_vector& W,
650  int order = 2, float regularization = 0.01F, bool extrapolate = true )
651  {
652  PCL_PRECONDITION( P1.Length() == D2.Length() )
653  PCL_PRECONDITION( P2.Length() == D1.Length() )
654  PCL_PRECONDITION( W.IsEmpty() || W.Length() >= P1.Length() )
655  m_LP1 = P1;
656  m_LD2 = D2;
657  m_LP2 = P2;
658  m_LD1 = D1;
659  m_LW = W;
660  m_localDistortionOrder = Max( 2, order );
661  m_localDistortionRegularization = Max( .0F, regularization );
662  m_localDistortionExtrapolation = extrapolate;
663  }
664 
671  {
672  return !m_LP1.IsEmpty();
673  }
674 
682  const String& Metadata() const
683  {
684  return m_metadata;
685  }
686 
693  void SetMetadata( const String& metadata )
694  {
695  m_metadata = metadata.Trimmed();
696  }
697 
711  const DVector& Location() const
712  {
713  return m_location;
714  }
715 
724  void SetLocation( const DVector& v )
725  {
726  m_location = v;
727  }
728 
742  const DVector& ReferenceLocation() const
743  {
744  return m_referenceLocation;
745  }
746 
754  void SetReferenceLocation( const DVector& v )
755  {
756  m_referenceLocation = v;
757  }
758 
783  const DVector& Scale() const
784  {
785  if ( !m_scale.IsEmpty() )
786  return m_scale;
787  if ( m_unitScale.IsEmpty() )
788  m_unitScale = DVector( 1.0, NumberOfChannels() );
789  return m_unitScale;
790  }
791 
799  void SetScale( const DVector& v )
800  {
801  m_scale = v;
802  }
803 
808  double Pedestal() const
809  {
810  return m_pedestal;
811  }
812 
818  void SetPedestal( double p )
819  {
820  m_pedestal = Range( p, 0.0, 1.0 );
821  }
822 
834  const DVector& Weight() const
835  {
836  if ( !m_weight.IsEmpty() )
837  return m_weight;
838  if ( m_unitWeight.IsEmpty() )
839  m_unitWeight = DVector( 1.0, NumberOfChannels() );
840  return m_unitWeight;
841  }
842 
850  void SetWeight( const DVector& v )
851  {
852  m_weight = v;
853  }
854 
861  bool HasIntegrationData() const
862  {
863  return !m_location.IsEmpty();
864  }
865 
872  bool HasImageWeightsData() const
873  {
874  return !m_weight.IsEmpty();
875  }
876 
889  {
890  return m_rejectionLowCount;
891  }
892 
905  {
906  return m_rejectionHighCount;
907  }
908 
956  const UInt8Image& RejectionMap() const
957  {
958  return m_rejectionMap;
959  }
960 
967  bool IsRejected( const Point& position, int channel = 0 ) const
968  {
969  return m_rejectionMap.Includes( position )
970  && m_rejectionMap.IsValidChannelIndex( channel )
971  && (m_rejectionMap( position, channel ) & 0x3F) != 0;
972  }
973 
981  void SetRejectionMap( const UInt8Image& map )
982  {
983  m_rejectionMap = map;
984  }
985 
990  bool HasRejectionData() const
991  {
992  return !m_rejectionMap.IsEmpty();
993  }
994 
1000  {
1001  return m_creationTime;
1002  }
1003 
1008  void Clear();
1009 
1015  void ClearIntegrationData();
1016 
1038  void Parse( const String& filePath, bool ignoreIntegrationData = false );
1039 
1059  void Parse( const XMLDocument& xml, bool ignoreIntegrationData = false );
1060 
1079  void Parse( const XMLElement& element, bool ignoreIntegrationData = false );
1080 
1092  {
1093  return m_compressionEnabled;
1094  }
1095 
1101  void EnableCompression( bool enable = true )
1102  {
1103  m_compressionEnabled = enable;
1104  }
1105 
1111  void DisableCompression( bool disable = true )
1112  {
1113  EnableCompression( !disable );
1114  }
1115 
1123  XMLDocument* Serialize() const;
1124 
1133  void SerializeToFile( const String& path ) const;
1134 
1135 private:
1136 
1137  String m_sourceFilePath;
1138  String m_cfaSourceFilePath;
1139  String m_cfaSourcePattern;
1140  String m_alignTargetFilePath;
1141  int m_referenceWidth = -1;
1142  int m_referenceHeight = -1;
1143  DPoint m_alignmentOrigin = 0.5;
1144  Matrix m_H;
1145  vector_spline m_S;
1146  vector_spline m_Sinv;
1147  distortion_vector m_LP1;
1148  distortion_vector m_LD2;
1149  distortion_vector m_LP2;
1150  distortion_vector m_LD1;
1151  weight_vector m_LW;
1152  int m_localDistortionOrder = 2;
1153  float m_localDistortionRegularization = 0.01F;
1154  bool m_localDistortionExtrapolation = true;
1155  String m_metadata;
1156  double m_pedestal = 0.0;
1157  Vector m_location;
1158  Vector m_referenceLocation;
1159  Vector m_scale;
1160  mutable Vector m_unitScale;
1161  Vector m_weight;
1162  mutable Vector m_unitWeight;
1163  UI64Vector m_rejectionLowCount;
1164  UI64Vector m_rejectionHighCount;
1165  UInt8Image m_rejectionMap;
1166  TimePoint m_creationTime;
1167  bool m_compressionEnabled = true;
1168 
1169  // Working data for spline deserialization.
1170  spline m_Sx;
1171  spline m_Sy;
1172  spline m_Sxinv;
1173  spline m_Syinv;
1174 
1175  // Working data for old text format compatibility.
1176  rejection_data m_rejectLowData;
1177  rejection_data m_rejectHighData;
1178 
1179  void ParseRejectionMap( const XMLElement& );
1180  void SerializeRejectionMap( XMLElement* ) const;
1181 
1182  static void ParseSpline( spline&, const XMLElement& );
1183  static void SerializeSpline( XMLElement*, const spline& );
1184 
1185  static distortion_vector ParseDistortionPoints( const XMLElement& );
1186  void SerializeDistortionPoints( XMLElement*, const distortion_vector& ) const;
1187 
1188  static weight_vector ParseDistortionWeights( const XMLElement& );
1189  void SerializeDistortionWeights( XMLElement*, const weight_vector& ) const;
1190 
1191  static ByteArray ParseMaybeCompressedData( const XMLElement& );
1192  void SerializeMaybeCompressedData( XMLElement* root,
1193  const void* data, size_type size, size_type itemSize = 1 ) const;
1194 
1200  class PlainTextDecoder
1201  {
1202  public:
1203 
1204  PlainTextDecoder( DrizzleData* data, bool ignoreIntegrationData )
1205  : m_data( data )
1206  , m_ignoreIntegrationData( ignoreIntegrationData )
1207  {
1208  }
1209 
1210  virtual ~PlainTextDecoder()
1211  {
1212  }
1213 
1214  void Decode( IsoString&, size_type start = 0, size_type end = 0 );
1215 
1216  protected:
1217 
1218  PlainTextDecoder() = default;
1219 
1220  private:
1221 
1222  DrizzleData* m_data = nullptr;
1223  bool m_ignoreIntegrationData = false;
1224 
1225  virtual void ProcessBlock( IsoString&, const IsoString&, size_type, size_type );
1226 
1227  static rejection_coordinates ParseRejectionCoordinates( IsoString&, size_type, size_type );
1228  static rejection_data ParseRejectionData( IsoString&, size_type, size_type );
1229  static spline ParseSurfaceSpline( IsoString&, size_type, size_type );
1230  };
1231 
1232  class PlainTextSplineDecoder : public PlainTextDecoder
1233  {
1234  public:
1235 
1236  PlainTextSplineDecoder( spline& S )
1237  : m_S( S )
1238  {
1239  }
1240 
1241  virtual ~PlainTextSplineDecoder()
1242  {
1243  }
1244 
1245  private:
1246 
1247  spline& m_S;
1248 
1249  void ProcessBlock( IsoString&, const IsoString&, size_type, size_type ) override;
1250  };
1251 };
1252 
1253 // ----------------------------------------------------------------------------
1254 
1255 } // pcl
1256 
1257 #endif // __PCL_DrizzleData_h
1258 
1259 // ----------------------------------------------------------------------------
1260 // EOF pcl/DrizzleData.h - Released 2020-07-31T19:33:04Z
bool IsEmpty() const
Definition: Array.h:314
void DisableCompression(bool disable=true)
Definition: DrizzleData.h:1111
bool IsRejected(const Point &position, int channel=0) const
Definition: DrizzleData.h:967
const DVector & Location() const
Definition: DrizzleData.h:711
const UI64Vector & RejectionLowCount() const
Definition: DrizzleData.h:888
void SetAlignmentSplines(const vector_spline &S)
Definition: DrizzleData.h:488
const DPoint & AlignmentOrigin() const
Definition: DrizzleData.h:413
int ReferenceHeight() const
Definition: DrizzleData.h:380
An instant in any timescale.
Definition: TimePoint.h:102
void SetRejectionMap(const UInt8Image &map)
Definition: DrizzleData.h:981
void GetLocalDistortionModel(distortion_vector &P1, distortion_vector &D2, distortion_vector &P2, distortion_vector &D1, weight_vector &W, int &order, float &regularization, bool &extrapolate)
Definition: DrizzleData.h:586
bool HasRejectionData() const
Definition: DrizzleData.h:990
DrizzleData(const XMLDocument &xml, bool ignoreIntegrationData=false)
Definition: DrizzleData.h:209
bool IsCompressionEnabled() const
Definition: DrizzleData.h:1091
PCL root namespace.
Definition: AbstractImage.h:76
const UI64Vector & RejectionHighCount() const
Definition: DrizzleData.h:904
int NumberOfChannels() const
Definition: DrizzleData.h:401
bool HasAlignmentSplines() const
Definition: DrizzleData.h:500
void SetReferenceDimensions(int width, int height)
Definition: DrizzleData.h:391
Dynamic array of 8-bit unsigned integers.
DrizzleData(const String &filePath, bool ignoreIntegrationData=false)
Definition: DrizzleData.h:187
bool HasIntegrationData() const
Definition: DrizzleData.h:861
XML document parsing and generation
Definition: XML.h:2560
void SetMetadata(const String &metadata)
Definition: DrizzleData.h:693
bool HasLocalDistortionModel() const
Definition: DrizzleData.h:670
void EnableCompression(bool enable=true)
Definition: DrizzleData.h:1101
void SetWeight(const DVector &v)
Definition: DrizzleData.h:850
constexpr const T & Range(const T &x, const T &a, const T &b)
Definition: Utility.h:190
size_t size_type
Definition: Defs.h:543
double Pedestal() const
Definition: DrizzleData.h:808
vector_spline::spline spline
Definition: DrizzleData.h:127
const String & SourceFilePath() const
Definition: DrizzleData.h:261
TimePoint CreationTime() const
Definition: DrizzleData.h:999
const Matrix & AlignmentMatrix() const
Definition: DrizzleData.h:441
64-bit floating point real matrix.
Array< Point > rejection_coordinates
Definition: DrizzleData.h:145
bool HasAlignmentInverseSplines() const
Definition: DrizzleData.h:537
void SetLocation(const DVector &v)
Definition: DrizzleData.h:724
Unicode (UTF-16) string.
Definition: String.h:7916
bool HasImageWeightsData() const
Definition: DrizzleData.h:872
void SetPedestal(double p)
Definition: DrizzleData.h:818
Array< float > weight_vector
Definition: DrizzleData.h:139
constexpr const T & Max(const T &a, const T &b)
Definition: Utility.h:119
void SetCFASourcePattern(const String &cfaPattern)
Definition: DrizzleData.h:328
64-bit floating point real vector.
void SetReferenceLocation(const DVector &v)
Definition: DrizzleData.h:754
Drizzle integration data parser and generator.
Definition: DrizzleData.h:112
void SetCFASourceFilePath(const String &filePath)
Definition: DrizzleData.h:298
Array< rejection_coordinates > rejection_data
Definition: DrizzleData.h:150
64-bit unsigned integer vector.
const DVector & Scale() const
Definition: DrizzleData.h:783
8-bit unsigned integer image.
void SetAlignmentMatrix(const Matrix &H)
Definition: DrizzleData.h:452
const String & AlignmentTargetFilePath() const
Definition: DrizzleData.h:349
const UInt8Image & RejectionMap() const
Definition: DrizzleData.h:956
XML element
Definition: XML.h:1137
64-bit floating point real vector.
void SetSourceFilePath(const String &filePath)
Definition: DrizzleData.h:272
Array< DPoint > distortion_vector
Definition: DrizzleData.h:133
size_type Length() const
Definition: Array.h:268
void SetLocalDistortionModel(const distortion_vector &P1, const distortion_vector &D2, const distortion_vector &P2, const distortion_vector &D1, const weight_vector &W, int order=2, float regularization=0.01F, bool extrapolate=true)
Definition: DrizzleData.h:647
64-bit floating-point point in the R^2 space.
void SetScale(const DVector &v)
Definition: DrizzleData.h:799
void SetAlignmentTargetFilePath(const String &filePath)
Definition: DrizzleData.h:360
int ReferenceWidth() const
Definition: DrizzleData.h:370
32-bit integer point on the plane.
const String & CFASourcePattern() const
Definition: DrizzleData.h:314
void SetAlignmentInverseSplines(const vector_spline &Sinv)
Definition: DrizzleData.h:525
const vector_spline & AlignmentInverseSplines() const
Definition: DrizzleData.h:513
const DVector & ReferenceLocation() const
Definition: DrizzleData.h:742
virtual ~DrizzleData()
Definition: DrizzleData.h:237
static String FullPath(const String &path)
const String & CFASourceFilePath() const
Definition: DrizzleData.h:287
void SetAlignmentOrigin(const DPoint &p0)
Definition: DrizzleData.h:429
const DVector & Weight() const
Definition: DrizzleData.h:834
bool HasAlignmentMatrix() const
Definition: DrizzleData.h:463
const vector_spline & AlignmentSplines() const
Definition: DrizzleData.h:476
const String & Metadata() const
Definition: DrizzleData.h:682
PointSurfaceSpline< DPoint > vector_spline
Definition: DrizzleData.h:121
DrizzleData(const XMLElement &element, bool ignoreIntegrationData=false)
Definition: DrizzleData.h:229
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5390